//
//  PickUpOrderController.m
//  LianShangBao
//
//  Created by 主事丫环HU on 2020/9/4.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "PickUpOrderController.h"
#import "PickUpOrderListCell.h"
#import "PickUpOrderDetailController.h"
#import "PickUpOrderListModel.h"
@interface PickUpOrderController ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation PickUpOrderController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.dataArray = [NSMutableArray arrayWithCapacity:0];
    [self requestPickUpOrderListData];
}
- (void)setupUI{
    self.title = @"提货订单";
    [self.leftbutton setImage:imgname(@"lefticon") forState:(UIControlStateNormal)];
     self.view.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
    
    self.tableView.rowHeight = 110;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView = [[UIView alloc] init];
}
- (void)requestPickUpOrderListData{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"userId"] = USER_ID;
    [NetWorkTool POST:getPickOrderList param:param success:^(id dic) {
        self.dataArray = [PickUpOrderListModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];
        [self.tableView reloadData];
    } other:^(id dic) {
        
    } fail:^(NSError *error) {
        
    } needUser:YES];
}
#pragma mark - tableview datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PickUpOrderListModel *model = self.dataArray[indexPath.row];
    PickUpOrderListCell *cell = [PickUpOrderListCell cellWithTableView:tableView];
    cell.model = model;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    PickUpOrderListModel *model = self.dataArray[indexPath.row];
    PickUpOrderDetailController * vc = [[PickUpOrderDetailController alloc] init];
    vc.model = model;
    [self.navigationController pushViewController:vc animated:YES];
}
@end
